<?
//phpinfo();
error_reporting(E_ALL);
function debug($var){
	echo '<div class="debug_div">::APPLICATION DEBUG START::<pre class="debug">';
	print_r($var);
	echo '</pre>::APPLICATION DEBUG END::</div>';
}

//echo PATH_SEPARATOR;
define ("SITE_ROOT",dirname(dirname(__FILE__)));
define('BASE_PATH', dirname(__FILE__));
define ('LIBS_PATH', BASE_PATH.DIRECTORY_SEPARATOR.'library'.DIRECTORY_SEPARATOR);

ini_set('include_path', BASE_PATH.DIRECTORY_SEPARATOR.'library'.PATH_SEPARATOR.BASE_PATH.DIRECTORY_SEPARATOR.'application'.DIRECTORY_SEPARATOR.'models'
					.PATH_SEPARATOR.ini_get('include_path'));

if(!is_dir(BASE_PATH.'/cache'))
    mkdir(BASE_PATH.'/cache',0777);
if(!is_dir(BASE_PATH.'/cache/adodb'))
    mkdir(BASE_PATH.'/cache/adodb', 0777);
if(!is_dir(BASE_PATH.'/cache/smarty'))
    mkdir(BASE_PATH.'/cache/smarty', 0777);
if(!is_dir(BASE_PATH.'/cache/images'))
    mkdir(BASE_PATH.'/cache/images', 0777);
if(!is_dir(BASE_PATH.'/cache/templates_c'))
    mkdir(BASE_PATH.'/cache/templates_c', 0777);


include "Zend/Loader.php";
require_once('Helpers/DataUtils.php');
require_once('Helpers/ImageUtils.php');
require_once('Helpers/StringUtils.php');
require_once('Controller/Action.php');
require_once('DataObject/DomainModel.php');
require_once('DataObject/ModelMapper.php');
require_once('DataObject/ObjectWatcher.php');
require_once('DataObject/ModelCollection.php');
require_once('DataObject/FactoryHelper.php');
	

$start = array_sum(explode(" ",microtime()));
Zend_Loader::loadClass('Zend_Controller_Front');
Zend_Loader::loadClass('Zend_Config_Xml');
Zend_Loader::loadClass('Zend_Config_Ini');
Zend_Loader::loadClass('Zend_Registry');
Zend_Loader::loadClass('Zend_Session_Namespace');
Zend_Loader::loadClass('Zend_Captcha_Image');
Zend_Loader::loadClass('Zend_Auth');
Zend_Loader::loadClass('ModelCollection');
Zend_Loader::loadClass('ModelMapper');
Zend_Loader::loadClass('DomainModel');
Zend_Loader::loadClass('ObjectWatcher');
Zend_Loader::loadClass('FactoryHelper');

$frontController = Zend_Controller_Front::getInstance();
$frontController->throwExceptions(true);
$frontController->setControllerDirectory('./application/controllers');

/**
 * Routes
*/
$router = $frontController->getRouter();
$router->addConfig(new Zend_Config_Ini(BASE_PATH.'/library/routes.ini'), 'routes');

$frontController->dispatch();

///////////////////////////////////////////////////////////////////////////////
/*
 * Compute and display page's generation time
 */
define('DISPLAY_STATS', true);

if (defined('DISPLAY_STATS') && !defined('DISPLAY_STATS_OFF') && DISPLAY_STATS) {
	if (function_exists('memory_get_usage')) {
		$strMemory = memory_get_usage()/1024;
	} else {
		$strMemory = 'no available memory_get_usage function';
	}

	$stop = array_sum(explode(" ",microtime()));
	$time = $stop-$start;
	echo "
		<!--
			Start time - $start
			Stop time - $stop
			Execution time: $time
			Memory usage - $strMemory Kb
		-->
	";
}